package com.login_1.dao.impl;

import com.login_1.dao.UserDao;
import com.login_1.pojo.User;
import com.login_1.util.DruidUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDaoImpl implements UserDao {

    private JdbcTemplate jt = new JdbcTemplate(DruidUtils.getDataSource());

    @Override
    public User findByUser(User user){
        try {
            User u = jt.queryForObject("select * from user where username = ? and password = ?",
                    new BeanPropertyRowMapper<User>(User.class),
                    user.getUsername(), user.getPassword());
            return u;
        } catch (Exception e) {
            System.out.println("数据库没有查到...");
        }
        return null;
    }
}
